<%--
  Created by IntelliJ IDEA.
  User: xiaoji
  Date: 2014/11/4
  Time: 11:14
  To change this template use File | Settings | File Templates.
--%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=UTF-8" language="java"  pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="spring" uri="/WEB-INF/lib/spring.tld"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %>
<%@ taglib prefix="z" uri="/WEB-INF/lib/zerdoor.tld"%>
<c:set value="${pageContext.request.contextPath}" var="path" scope="page"/>
<html>
<head>
    <title><spring:message code="bid.head"/></title>
    <link rel="stylesheet" media="screen" href="${path}/plugins/validate/validate.css">
    <link href="${path}/style/acg/css/style.css" rel="stylesheet" type="text/css" />
    <script src="${path}/js/jquery.min.js" type="text/javascript"></script>
    <script src="${path}/plugins/validate/jquery.validate.min.js" type="text/javascript"></script>
    <c:if test="${ sessionScope.language != 'en'}">
        <script src="${path}/plugins/validate/messages_cn.js" type="text/javascript"></script>
    </c:if>
    <!-- 文件上传JS -->
    <script type="text/javascript" src="${path}/js/ajaxfileupload.js"></script>
    <script type="text/javascript">
        //删除上传图片
        function deleteImg(num){
            //删除元素
            var url = $("#img"+num).attr("surl");
            $("#img"+num).remove();
            //为隐藏变量重新赋值
            var attachment = $("#attachment").val();
            var attachment2="";
            var indexa = attachment.indexOf(attachment);
            if(indexa != -1){
                var arr = attachment.split(",");
                if(arr.length >0 ){
                    for(var i=0; i<arr.length; i++){
                        var tempobj = arr[i];
                        if(url == arr[i]){
                            arr.splice(i,1);
                        }
                    }
                }
                console.log(arr);
                attachment2 = arr.join(",");
                $("#attachment").val(attachment2);
            }
        }
        //上传图片
        var uploadnum = 1;
        function f_file_upload(){
            $.ajaxFileUpload({
                url: '${path}/fileUpload/upload_resource_file.html',
                secureuri: false,
                fileElementId: 'fulAchievements',
                success: function (data) {
                    //data = $.parseJSON(data);
                    var data2 = data.split(",");
                    var url = data2[0].replace(" ","");
                    var fileName = data2[1].replace(" ","");

                    var imgs = ".bmp.jpg.dib.jpeg.png.jfif.jpe.tif.tiff.gif.BMP.JPG.DIB.JPEG.PNG.JFIF.JPE.TIF.TIFF.GIF";
                    var rars = ".rar.zip.7z.cab.txt.doc.docx.xls.xlsx.RAR.ZIP.7Z.CAB.TXT.DOC.DOCX.XLS.XLSX";
                    var suffix = url.substring(url.lastIndexOf("."));
                    var showUrl = "style/common/images/yasuobao.png";
                    if(imgs.indexOf(suffix) != -1){
                        showUrl=url
                    }
                    var htmlStr = '<li id="img'+uploadnum+'" surl="'+url+'">'+
                                    '<img src="${path}/'+showUrl+'" width="56" height="70" />'+
                                    '<p>'+fileName+'</p>'+
                                    '<span class="ico_del" onclick="deleteImg('+uploadnum+')">×</span>'+
                                    '</li>';
                    $("#showPic").append(htmlStr);
                    if($("#attachment").val() == ''){
                        $("#attachment").val(url);
                    }else{
                        $("#attachment").val($("#attachment").val()+","+url);
                    }
                    uploadnum++;
                    //给图片绑定事件
                },
                error:function(data){

                }
            });
        }

        $(function(){
            var validate = $("#frm").validate({
                rules : {
                    budget:{
                        required: true,
                        number:true
                    },
                    cycle:{
                        required: true,
                        number:true
                    },
                    pieceNum:{
                        min:0,
                        max:${taskinfo.pieceNum},
                        number:true
                    },
                    selfDescription:{
                        required: true
                    },
                    agree: "required"
                },
                messages : {

                },
                success: function(label) {//验证成功添加样式
                    label.html("&nbsp;").removeClass("checked").addClass("checked");
                },
                submitHandler : function(){
                    $.post("${path}/bid/addBidInfo.html",
                            $("#frm").serialize()
                            ,function(data){
                                if(data.status == 0){
                                    alert("<spring:message code="bid.result_success"/>");
                                    window.location = "${path}/taskdetail/index.html?taskId="+${taskinfo.itemId};
                                }else{
                                    alert("<spring:message code="bid.result_fail"/>");
                                }
                            },"json");
                }
            });
        });
    </script>
</head>
<body>
<jsp:include page="../public/header.jsp"></jsp:include>
<!--content-->
<form id="frm">
<div id="container">
    <div class="wrapper">
        <div class="referbidbox">
            <div class="referform">
                <h1>${taskinfo.title }</h1>
                <p>
                    <spring:message code="bid.task_id"/>：${taskinfo.itemId}&nbsp;&nbsp;&nbsp;
                    <c:if test="${taskinfo.pieceNum != null}"><spring:message code="bid.pieceNum"/>：${taskinfo.pieceNum}</c:if>
                    <input type="hidden" name="taskId" value="${taskinfo.itemId}" />
                </p>
            </div>
            <div class="referform">
                <ul>
                    <li class="formli">
                        <dl class="clearfix">
                        <dt style="text-align: left${sessionScope.language == "en"?";width:250px":""}" ><h2><spring:message code="bid.budget"/></h2></dt>
                        <dd style="width:auto"><input type="text" name="budget" id="budget" value="" class="input_txt" style="width: 250px"/>&nbsp;人民币</dd>
                        </dl>
                     </li>
                    <li class="formli">
                        <dl class="clearfix">
                            <dt style="text-align: left${sessionScope.language == "en"?";width:250px":""}"><h2><spring:message code="bid.cycle"/></h2></dt>
                            <dd style="width:auto" ><input type="text" name="cycle" id="cycle" value="" class="input_txt" style="width: 250px"/>&nbsp;天</dd>
                        </dl>
                    </li>
                    <c:if test="${taskinfo.pieceNum != null}">
                        <li class="formli">
                            <dl class="clearfix">
                                <dt style="text-align: left${sessionScope.language == "en"?";width:250px":""}"><h2><spring:message code="bid.pieceNumInput"/></h2></dt>
                                <dd style="width:auto"><input type="text" name="pieceNum" id="pieceNum" value="" class="input_txt" style="width: 500px"/></dd>
                            </dl>
                        </li>
                    </c:if>
                    <li><h2><spring:message code="bid.bid_info"/></h2></li>
                    <li><textarea name="selfDescription" id="selfDescription" cols="" rows="" style=" width:100%; height:328px" ></textarea></li>
                </ul>
            </div>
            <div class="referform">
                <ul>
                    <li><h2><spring:message code="bid.attachment"/></h2></li>
                    <li>
                        <div class="project_files">
                            <ul class="clearfix" id="showPic">

                            </ul>
                        </div>
                    </li>
                    <li class="clearfix">
                        <label for="fulAchievements"   class="btn_addfile"><spring:message code="bid.add_attachment"/></label>
                        <input style="display: none" type="file" name="file" id="fulAchievements" onchange="f_file_upload()"  />
                        <input type="hidden" name="attachment" id="attachment" value="">
                    </li>
                </ul>
            </div>
            <div class="referform">
                <ul>
                    <li><h2><spring:message code="bid.rules"/>：</h2></li>
                    <li class="refer_Rule">
                        <spring:message code="bid.contract_rules"/>
                    </li>
                    <li class="refer_green">
                        <input type="checkbox" name="agree" id="agree"  />
                        <label><spring:message code="bid.contract_agreed"/></label>
                    </li>
                </ul>
            </div>
            <div class="refersubmit">
                <input type="submit" id="" name="" class="btnrefer" value="<spring:message code="bid.button"/>" />
                <!--<a href="" class="btnrefer">提交投标</a>-->
            </div>
        </div>
    </div>
</div>
</form>
<!--content-->
<jsp:include page="../public/footer.jsp"></jsp:include>
</body>
</html>
